from qiniu import Auth, put_data

# ap接口
access_key = 'wuloqtHQUiN63qiZft1ea9relilQiLlFPJvdH408'
secret_key = '5CI_fIfCYCL5qRzaFTUykbx0EK7mqlmIEY50imT1'
bucket = 'information-img'


def storage(data):
    try:
        q = Auth(access_key, secret_key)
        token = q.upload_token(bucket)
        ret, info = put_data(token, None, data)
        print(ret, info)
    except Exception as e:
        raise e

    if info.status_code != 200:
        raise Exception('上传图片失败')
    return ret['key']


if __name__ == '__main__':
    file = input('请输入文件路径')
    with open(file, 'rb') as f:
        storage(f.read())
